* Firm organization with multiple establishments
* Appendix A: Tables A.27-A.30

clear all 
set matsize 2000
set more off

capture log close
log using log/37_cmrh-p_replication_hq_layer-est.log, replace

* Use establishment-level dataset

use data/CMRH_2000-2010_p_est_layer-est.dta if hauptbet == 1, clear

duplicates report betnr jahr

*Table A.27: # employees are hierarchical
**************************************

gen h01 = (empl_lyr0>=empl_lyr1 & empl_lyr0~=.)
gen h12 = (empl_lyr1>=empl_lyr2 & empl_lyr1~=.)
gen h23 = (empl_lyr2>=empl_lyr3 & empl_lyr2~=.)

*
*fraction of est satisfying hierarchy
*In each cell:
* - first element: number of obs in cell
* - second element: fraction of est with 1

tabstat h01 h12 h23  if count_mgmt_est>0, by(count_mgmt_est) format(%12.3f) statistics(N mean)

count if h01 == 1 & h12 == 1 & count_mgmt_est == 2
count if h01 == 1 & h12 == 1 & h23 == 1 & count_mgmt_est == 3

table count_mgmt_est, c(sum h01 sum h12 sum h23)


*Table A.28: # employees are hierarchical, restricted sample
**************************************
*	re-run as before but sub-set to establishments where all ranks defined at establishment-level are equal to ranks defined at firm-level

*
*fraction of firms satisfying hierarchy
*In each cell:
* - first element: number of obs in cell
* - second element: fraction of firms with 1

tabstat h01 h12 h23  if count_mgmt_est>0 & same_rank_unt_est == 1, by(count_mgmt_est) format(%12.3f) statistics(N mean)

count if h01 == 1 & h12 == 1 & count_mgmt_est == 2 & same_rank_unt_est == 1
count if h01 == 1 & h12 == 1 & h23 == 1 & count_mgmt_est == 3 & same_rank_unt_est == 1

table count_mgmt_est if same_rank_unt_est == 1, c(sum h01 sum h12 sum h23)

drop  h01 h12 h23
******************** end tables

*Table A.29: wages are hierarchical
****************************************
*
gen h01 = (avg_wage_lyr0<=avg_wage_lyr1 & avg_wage_lyr1~=.)
gen h12 = (avg_wage_lyr1<=avg_wage_lyr2 & avg_wage_lyr2~=.)
gen h23 = (avg_wage_lyr2<=avg_wage_lyr3 & avg_wage_lyr3~=.)


*fraction of firms satisfying hierarchy
*In each cell:
* - first element: number of obs in cell
* - second element: fraction of firms with 1

tabstat h01 h12 h23  if count_mgmt_est>0, by(count_mgmt_est) format(%12.3f) statistics(N mean)

count if h01 == 1 & h12 == 1 & count_mgmt_est == 2
count if h01 == 1 & h12 == 1 & h23 == 1 & count_mgmt_est == 3

table count_mgmt_est, c(sum h01 sum h12 sum h23)

*Table A.30: wages are hierarchical, restricted sample
**************************************
*	re-run as before but sub-set to establishments where all ranks defined at establishment-level are equal to ranks defined at firm-level

*fraction of firms satisfying hierarchy
*In each cell:
* - first element: number of obs in cell
* - second element: fraction of firms with 1

tabstat h01 h12 h23  if count_mgmt_est>0 & same_rank_unt_est == 1, by(count_mgmt_est) format(%12.3f) statistics(N mean)

count if h01 == 1 & h12 == 1 & count_mgmt_est == 2 & same_rank_unt_est == 1
count if h01 == 1 & h12 == 1 & h23 == 1 & count_mgmt_est == 3 & same_rank_unt_est == 1

table count_mgmt_est if same_rank_unt_est == 1, c(sum h01 sum h12 sum h23)

******************** end tables

log close

clear all
